﻿@using CuongHanh.Context
@using CuongHanh.Models
@{
    List<OrderDetailForGem> models = CartAndPaymentContext.GetBagInfoOfGem(Session);
    long subTotal = 0;
    long total = 0;
    int index = 0;
}

<script type="text/javascript">
    $(document).ready(function() {
        $('.itemCount').change(function() {
            $('#gem-cart-info').load('@Url.Action("CartInfoOfGem")',{id:$(this).attr('refId'),count:$(this).val()});
        });

       
        $(".itemCount").keydown(function (e) {
            // Allow: backspace, delete, tab, escape, enter and .
            if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110]) !== -1 ||
                // Allow: Ctrl+A
                (e.keyCode == 65 && e.ctrlKey === true) ||
                // Allow: home, end, left, right
                (e.keyCode >= 35 && e.keyCode <= 39)) {
                // let it happen, don't do anything
                return;
            }
            // Ensure that it is a number and stop the keypress
            if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
                e.preventDefault();
            }
        });
    });
    function removeCartItem(id) {
        $('#gem-cart-info').load('@Url.Action("RemoveCartItemOfGem")', { id: id });
     }  
</script>
<table width="98%" border="0" cellpadding="0" cellspacing="0" class="cart">
    <tr>
        <th width="12%" align="left" scope="col">@Html.GetResource("cartitem")</th>
        <th width="21%" align="center" class="item2" scope="col">@(Html.GetResource("price")) (VND)</th>
        <th width="23%" align="center" scope="col">@Html.GetResource("quantity")</th>
        <th width="18%" align="right" scope="col">@(Html.GetResource("total")) (VND)</th>
    </tr>
    @foreach (OrderDetailForGem item in models)
    {
        index++;
        subTotal += item.GetTotalPrice;
        <tr>
            <td><a class="bg_img" href="javascript:void(0);"><img src="@Url.Action("GetImageFromData",
                                                                               "Gem",
                                                                               new
                                                                               {
                                                                                       parentStyleId = item.ParentStyleId,
                                                                                       parentMaterialId = item.ParentMaterialId,
                                                                                       parentStoneId = item.ParentStoneId,
                                                                                       childStyleId = item.ChildStyleId,
                                                                                       childMaterialId = item.ChildMaterialId,
                                                                                       childStoneId = item.ChildStoneId,
                                                                                       isThumnail = true
                                                                               })" width="70" height="69" /></a></td>

            <td align="center" id="item-price-@index" ref="@(item.GetPrice)">
                @if(item.ParentSize > 0)
                {
                    <label>@Html.GetResource("size"):</label>
                    <label>@item.ParentSize</label>
                    <br/>
                }
                @Html.GetResource("price"): @(item.GetPrice.FormatNumber())
                <br/>
                <a href="javascript:void(0);" onclick="removeCartItem(@item.Id);">@Html.GetResource("remove")</a>
            </td>
            <td align="center"><input type="text" class="itemCount" ref="@index" refId="@(item.Id)" value="@item.Count"/></td>
            <td align="right"><span id="item-total-price-@index" class="quality">@(item.GetTotalPrice.FormatNumber())<a class="up"></a><a class="down"></a></span></td>
        </tr>
    }

    <tr>
        <td colspan="3" align="right" class="sum"><span class="cart_note"><strong>@Html.GetResource("total")</strong></span>    
        <td align="right" class="sum"><strong>@subTotal.FormatNumber()</strong></td>
    </tr>
</table>